<%@page import="helpers.UrlHelper"%>
<%@page import="models.LinkModel"%>
<%@page import="models.CategoryModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
ArrayList<CategoryModel> categories = (ArrayList<CategoryModel>) request.getAttribute("categories");
String success = (String) request.getAttribute("success");
LinkModel link = (LinkModel) request.getAttribute("link");
String form = (String) request.getAttribute("form");
String action = "/admin/add-link";
if (form.equalsIgnoreCase("edit")) {
	action = "/admin/edit-link/" + link.getId();
}
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/form_link.js"></script>
<script type="text/javascript">
var server = "<%=UrlHelper.getServerUrl(request)%>";
</script>
	<% if (success != null) {%>
	<div class="success block" ><%=success %></div>
	<% } %>
	<div class="block">
		<form id="edit_link_form" action="<%=action %>" method="post">
			<table class="formPage">
				<thead>
					<tr>
						<th colspan="2">
							Create new link
						</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="label"><label for="link_type">Link Type:</label></td>
						<td class="smallDesc type">
							<%=check.get("type") != null ? check.get("type") + "<br />" : "" %>
							<select id="link_type" name="type" <%=form.equalsIgnoreCase("edit") ? "disabled=\"disabled\"" : "" %>>
								<option <%=link.getType() != null && link.getType().equals("free") ? "selected=\"selected\"" : "" %> value="free">Free Link</option>
								<option <%=link.getType() != null && link.getType().equals("reciprocal") ? "selected=\"selected\"" : "" %> value="reciprocal">Free Link With Reciprocal</option>
								<option <%=link.getType() != null && link.getType().equals("featured") ? "selected=\"selected\"" : "" %> value="featured">Featured Link</option>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
			<div id="add_items">
				<table class="formPage">
					<tbody>
						<tr>
							<td class="label"><label for="TITLE">Title:</label></td>
							<td class="smallDesc">
								<%=check.get("name") != null ? check.get("name") + "<br />" : "" %>
								<input id="TITLE" class="text" type="text" name="name" value="<%=link.getName()%>" maxlength="100">
							</td>
						</tr>
						<tr>
							<td class="label"><label for="URL">Url:</label></td>
							<td class="smallDesc">
								<%=check.get("url") != null ? check.get("url") + "<br />" : "" %>
								<input id="URL" class="text" type="text" name="url" value="<%=link.getUrl() == null ? "" : link.getUrl() %>" maxlength="100">
								<a href="#" class="get-info">Get info</a>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="CATEGORY">Category:</label></td>
							<td class="smallDesc">
								<%=check.get("category") != null ? check.get("category") + "<br />" : "" %>
								<select name="category" id="CATEGORY">
									<option value="0">(TOP)</option>
									<%
									for (int i = 0; i < categories.size(); i++) {
									%>
									<option value="<%=categories.get(i).getId()%>" <%=categories.get(i).getId() == link.getCategory()? "selected=\"selected\"" : "" %>>
										|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
										<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
									</option>
									<%
									}
									%>
								</select>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="DESCRIPTION">Description:</label></td>
							<td class="smallDesc">
								<%=check.get("desc") != null ? check.get("desc") + "<br />" : "" %>
								<textarea id="DESCRIPTION" class="text" cols="80" rows="7" name="desc"><%=link.getDesc() == null ? "" : link.getDesc() %></textarea>
							</td>
						</tr>
						<tr class="thead">
							<th colspan="2">&nbsp;</th>
						</tr>
						<tr class="thead">
							<td class="info notice" colspan="2">Define custom META tags for detail pages. Leave blank to use default tags defined for your directory.</td>
						</tr>
						<tr>
							<td class="label"><label for="keywords">META Keywords:</label></td>
							<td class="smallDesc">
								<%=check.get("keywords") != null ? check.get("keywords") + "<br />" : "" %>
								<input name="keywords" id="keywords" value="<%=link.getKeywords() == null ? "" : link.getKeywords() %>" class="text" maxlength="200" />
								<p class="msg notice info">Separate keywords by comma.</p>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="metaDesc">META Description:</label></td>
							<td class="smallDesc">
								<%=check.get("metaDesc") != null ? check.get("metaDesc") + "<br />" : "" %>
								<textarea name="metaDesc" id="metaDesc" class="text"><%=link.getMetaDesc() == null ? "" : link.getMetaDesc() %></textarea> 
							</td>
						</tr>
						<tr class="reciprocal">
							<td class="label"><label for="reciprocal">Reciprocal Link:</label></td>
							<td class="smallDesc">
								<%=check.get("urlReciprocal") != null ? check.get("urlReciprocal") + "<br />" : "" %>
								<input type="text" name="urlReciprocal" value="" class="text">
								<p>To validate the reciprocal link please include the following HTML code in the page at the URL specified above, <br />before submiting this form:</p>
								<textarea type="text" name="sourceReciprocal" class="text"><a href="http://www.linkdirectory.com">Link directory</a></textarea> 
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<table class="formPage">
				<tbody>
					<tr>
						<td class="label"><label for="STATUS">Status:</label></td>
						<td class="smallDesc">
							<select id="STATUS" name="status">
								<option value="0" label="Inactive">Inactive</option>
								<option value="1" label="Pending">Pending</option>
								<option selected="selected" value="2" label="Active">Active</option>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
			<table class="formPage">
				<tfoot>
					<tr>
						<td><input type="reset" class="button" title="Reset form" alt="Reset form" value="Reset" name="reset" id="reset-link-submit"></td>
						<td><input type="submit" class="button" title="Save link" alt="Save form" value="Save" name="save" id="send-link-submit"></td>
					</tr>
				</tfoot>
			</table>
		</form>
	</div>
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>